var musicList = new Array();
var music;
var musicIndex;
var musicHtml;
var musicSound;

function musicHome(divid){
	$("#"+divid).unbind("click");
	$("#"+divid).empty();
	musicHtml = '<div class="ui360 ui360-vis" style="margin:0 auto;padding-left:0px;"><a style="float:left;width:90%;color:#fff;text-aligh:center;display:none;" id="music_a" href="xxx.mp3"></a></div>';
	musicHtml += '<div onclick="gotoMusic(\'component7\');" class="musci_text" style="position: absolute; bottom: 5%; right: 10px;">音乐</div>';
	musicHtml += '<div class="musci_text" id="music_info" style="position: absolute; bottom: 5%; left: 30%;"></div>';
	musicHtml += '<div onclick="playLast();" style="position: absolute;width:30%;bottom: 15%;left: 5%;font-size: 18px;height:50px;"><img src="compents/music/images/play-pre.png" style="width:36px;"/></div>';
	musicHtml += '<div onclick="playNext();" style="position: absolute;width:30%;bottom: 15%;right: 5%;font-size: 18px;height:50px;"><img src="compents/music/images/play-next.png" style="width:36px;"/></div>';
	$("#"+divid).append(musicHtml);
	threeSixtyPlayer.playButtonEle = $('#music_a')[0];
	$.getJSON("music_getDefaultMusiclist.do",{},function(json){
		for(var i=0;i<json.length;i++){
			musicList.push(json[i]);
			threeSixtyPlayer.urls.push(json[i].mp3url);
		}
	});
	initSoundManager();
	threeSixtyPlayer.playFinishCallback = function(){
		showMusicInfo();
	};
	$(".ui360").click(function(){
		if(!musicSound){
			musicSound = threeSixtyPlayer.lastSound;
			showMusicInfo();
		}
	});
	musicRefreash();
	
}

function showMusicInfo(){
	musicIndex = threeSixtyPlayer.index;
	music = musicList[musicIndex];
	$("#music_info").empty();
	$("#music_info").append(music.songName+"-"+music.singerName);
}

function musicRefreash(){
	var width = $("#component7").width();
	var height = $("#component7").height();
	//$(".ui360-vis,.ui360-vis .sm2-360ui,.sm2-inline-list .ui360-vis").css("height",height*0.75);
	//$(".ui360-vis,.ui360-vis .sm2-360ui,.sm2-inline-list .ui360-vis").css("width",height*0.75);
	//$(".sm2-inline-list .ui360-vis a,.ui360-vis .sm2-timing").css("line-height",height*0.75+"px");
	
	$(".musci_text").css("line-height",height/6+"px");
	$(".musci_text").css("font-size",height/12+"px");
	if (threeSixtyPlayer.lastSound) {
		//threeSixtyPlayer.lastSound._360data.circleDiameter = width*0.6;
 		//threeSixtyPlayer.lastSound._360data.circleRadius = width*0.3;
	}
	
	
	

}

function gotoMusic(id){
	showWin("music1","compents/music/main.html");
	if($("#music1_imgTool").length!=0){
		return;
	}
	var img = '<img id="music1_imgTool" title="音乐" src="image/cover/media/white/MB_0014_iTunes.png" style="width:60px;height:60px;cursor:pointer;float:left;padding-top:20px;"  onclick="showComponent(\''+id+'\')"/> ';
	$("#toolimgdiv").append(img);
}

function playNext(){
	if(musicSound){
		threeSixtyPlayer.stopSound(musicSound);
		musicSound = threeSixtyPlayer.playNext();
		showMusicInfo();
	}
	
}

function playLast(){
	if(musicSound){
		threeSixtyPlayer.stopSound(musicSound);
		musicSound = threeSixtyPlayer.playLast();
		showMusicInfo();
	}
	
}

function addAllToplay(musicJsons){
	for(var i=0;i<musicJsons.length;i++){
		var musicJson = musicJsons[i];
		musicList.push(musicJson);
		threeSixtyPlayer.urls.push(musicJson.mp3url);
	}
	if(musicSound){
		threeSixtyPlayer.stopSound(musicSound);
	}
	threeSixtyPlayer.initUrls();
	var index = threeSixtyPlayer.urls.length-musicJsons.length;
	musicSound = threeSixtyPlayer.playIndex(index);
	showMusicInfo();
}

function addToplay(musicJson){
	musicList.push(musicJson);
	threeSixtyPlayer.urls.push(musicJson.mp3url);
	if(musicSound){
		threeSixtyPlayer.stopSound(musicSound);
	}
	threeSixtyPlayer.initUrls();
	var index = threeSixtyPlayer.urls.length-1;
	musicSound = threeSixtyPlayer.playIndex(index);
	showMusicInfo();
}

function initSoundManager(){
	soundManager.url = 'compents/music/360-player/swf/'; 
	soundManager.useFastPolling = true; 
	
	threeSixtyPlayer.config = {
		playNext : true,
		autoPlay : false,
		allowMultiple : false,
		loadRingColor : '#FFFFFF',
		playRingColor : '#FFFF88',
		backgroundRingColor : '#E6E6E6',
		circleDiameter : 100,
		circleRadius : 50,
		animDuration : 500,
		animTransition : Animator.tx.bouncy,
		showHMSTime : true,

		useWaveformData : true,
		waveformDataColor : '#37D431',
		waveformDataDownsample : 2,
		waveformDataOutside : false,
		waveformDataConstrain : false,
		waveformDataLineRatio : 0.3,

		useEQData : true,
		eqDataColor : '#FAC967',
		eqDataDownsample : 4,
		eqDataOutside : true,
		eqDataLineRatio : 0.4,

		usePeakData : true,
		peakDataColor : '#ff33ff',
		peakDataOutside : true,
		peakDataLineRatio : 0.5,

		useAmplifier : true
	}

	if (threeSixtyPlayer.config.useWaveformData) {
	  soundManager.flash9Options.useWaveformData = true;
	}
	if (threeSixtyPlayer.config.useEQData) {
	  soundManager.flash9Options.useEQData = true;
	}
	if (threeSixtyPlayer.config.usePeakData) {
	  soundManager.flash9Options.usePeakData = true;
	}
	if (threeSixtyPlayer.config.useWaveformData || threeSixtyPlayer.flash9Options.useEQData || threeSixtyPlayer.flash9Options.usePeakData) {
	  soundManager.preferFlash = true;
	}

	if (window.location.href.match(/hifi/i)) {
	  threeSixtyPlayer.config.useFavIcon = true;
	}

	if (window.location.href.match(/html5/i)) {
	  soundManager.useHTML5Audio = true;
	}
}

